<?php
/**
 * Created by PhpStorm.
 * User: wuxiang
 * Date: 2016/7/13
 * Time: 14:28
 * 运营后台渠道包
 */

namespace Channel\Controller;

use Common\Controller\AdminbaseController;
use Common\Libiary\BaseApiHttp;
use Common\Libiary\LogEX;
use Common\Libiary\Uploadify;
use Common\Libiary\ConfigMessage;

class PackageController extends AdminbaseController
{
    public $url = '';
    public $data = [];
    public $arr = [];
    public $page = 1;
    public $type;
    public $demain = TP_DEBUG ?  "http://m.9now.net/" : "http://m.mwee.cn/";

    function index(){
        $baseApi = new BaseApiHttp();
        $this->data = $baseApi->build_sparams();
        $this->url = $this->demain . 'api/operate/package/index';

        $this->page = I('get.Page',1,'intval');

        $this->data['Page'] = $this->page;

        $ret = $baseApi->https($this->url, 'POST', $this->data);
        $this->list = json_decode($ret, true);
        $this->display();
    }

    //获取更多
    function getMore(){
        $baseApi = new BaseApiHttp();
        $this->data = $baseApi->build_sparams();
        $this->url = $this->demain . 'api/operate/package/index';

        $this->page = I('Post.Page',1,'intval');

        $this->data['Page'] = $this->page;

        $ret = $baseApi->https($this->url, 'POST', $this->data);
        $this->list = json_decode($ret, true);

        $this->ajaxReturn($this->list);
    }

    function add(){
        $this->Type = I('get.Type','1','intval');
        $this->assign('Type',$this->Type);
        $this->display();
    }

    function addHandel(){

        $baseApi = new BaseApiHttp();
        $this->data = $baseApi->build_sparams();
        $this->url = $this->demain . 'api/operate/package/addhandel';

        $this->data['Name'] = I('post.Name','');
        $this->data['PackageName'] = I('post.PackageName');
        $this->data['ExpirationTime'] = I('post.OnTime',0);

        $this->data['Type'] = I('post.Type',1);
        $this->data['Forever'] = $this->data['Type']==2 ? 1 : I('post.Forever',0);
        $this->data['WeiXinUrl'] = I('post.WeiXinUrl','');

        //管理员信息
        $this->data['ADMIN_ID'] = $_SESSION['ADMIN_ID'];
        $this->data['ADMIN_USERNAME'] = $_SESSION['ADMIN_USERNAME'];
        $this->data['LAST_LOGIN_TIME'] = $_SESSION['LAST_LOGIN_TIME'];

        LogEX::i('渠道包添加',['data'=>$this->data],__FILE__,__LINE__);

        $ret = $baseApi->https($this->url, 'POST', $this->data);
        $this->list = json_decode($ret, true);

        $this->ajaxReturn($this->list);

    }

    /**
     * 上传包
     */
    public function uploadify()
    {
        $upload = new Uploadify();
        $arr = $upload->uploadifyFile($_FILES['coverImg']);
        $data = [
            'res' => 0,
            'info' => $arr
        ];
        $this->ajaxReturn($data);
    }

    //查看

    function view(){


        $baseApi = new BaseApiHttp();
        $this->data = $baseApi->build_sparams();
        $this->url = $this->demain . 'api/operate/package/view';

        $this->data['ChannelId'] = I('get.ChannelId',1,'intval');

        $this->data['Type'] = I('get.Type',1,'intval');

        $ret = $baseApi->https($this->url, 'POST', $this->data);

        $this->list = json_decode($ret, true);

        if(isset($_GET['debug'])){

            var_dump($ret);
            var_dump($this->list);
            print_r($this->list);
            exit;

        }

        $this->assign('Type',$this->Type);
        $this->display();
    }

    //编辑
    function editPackage(){
        $baseApi = new BaseApiHttp();
        $this->data = $baseApi->build_sparams();
        $this->url = $this->demain . 'api/operate/package/edit';

        $this->data['Name'] = I('post.Name');
        $this->data['PackageName'] = I('post.PackageName');
        $this->data['OnTime'] = I('post.OnTime',0);
        $this->data['ChannelId'] = I('post.ChannelId');

        $this->data['Type'] = I('post.Type',1);
        $this->data['Forever'] = $this->data['Type']==2 ? 1 : I('post.Forever',0);
        $this->data['WeiXinUrl'] = I('post.WeiXinUrl','');

        //管理员信息
        $this->data['ADMIN_ID'] = $_SESSION['ADMIN_ID'];
        $this->data['ADMIN_USERNAME'] = $_SESSION['ADMIN_USERNAME'];
        $this->data['LAST_LOGIN_TIME'] = $_SESSION['LAST_LOGIN_TIME'];

        $ret = $baseApi->https($this->url, 'POST', $this->data);
        $this->list = json_decode($ret, true);
        $this->ajaxReturn($this->list);

    }



}

